package com.turnengine.client.local.message.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Local Message Serializer.
 */
public class LocalMessageSerializer implements ILocalMessageSerializer {

	@Override
	public ILocalMessage readObject(IDataReader reader) throws IOException {

		// Read fields
		ILocalMessageHeader header = new LocalMessageHeaderSerializer().readObject(reader);
		ILocalMessageContent content = new LocalMessageContentSerializer().readObject(reader);

		// Create object
		ILocalMessage object = new LocalMessage();
		object.setHeader(header);
		object.setContent(content);
		return object;
	}

	public void writeObject(IDataWriter writer, ILocalMessage object) throws IOException {

		// Get fields
		ILocalMessageHeader header = object.getHeader();
		ILocalMessageContent content = object.getContent();

		// Write fields
		new LocalMessageHeaderSerializer().writeObject(writer, header);
		new LocalMessageContentSerializer().writeObject(writer, content);
	}
}
